package cn.tedu.suppermemory.controller;

import cn.tedu.suppermemory.pojo.dto.SubjectsAddDTO;
import cn.tedu.suppermemory.pojo.dto.SubjectsUpdateDTO;
import cn.tedu.suppermemory.pojo.vo.SubjectsListItemVO;import cn.tedu.suppermemory.pojo.vo.SubjectsStandardVO;
import cn.tedu.suppermemory.service.ISubjectsService;
import cn.tedu.suppermemory.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/subjects")
@Slf4j
@Api(tags = "课程管理模块")
public class SubjectsController {
    @Autowired
    private ISubjectsService subjectsService;
    @PostMapping("/add-new")
    @ApiOperation("添加课程")
    @ApiOperationSupport(order = 200)
    public JsonResult addNew(@Validated SubjectsAddDTO subjectsAddDTO){
        log.debug("开始处理【添加课程】的请求，参数：{}",subjectsAddDTO);
        subjectsService.addNew(subjectsAddDTO);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/delete")
    @ApiOperation("删除课程")
    @ApiOperationSupport(order = 210)
    @ApiImplicitParam(name = "id",value = "课程id",example = "1")
    public JsonResult delete(@PathVariable Long id){
        log.debug("开始处理【删除课程】的请求，参数：{}", id);
        subjectsService.delete(id);
        return JsonResult.ok();
    }

    @PostMapping("/{id:[0-9]+}/update")
    @ApiOperation("修改班级详情")
    @ApiOperationSupport(order = 220)
    public JsonResult updateInfoById(@PathVariable long id, @Validated SubjectsUpdateDTO subjectsUpdateDTO){
        log.debug("开始处理【根据id修改课程详情】的请求，参数：{}",subjectsUpdateDTO);
        subjectsService.updateInfoSubjects(id,subjectsUpdateDTO);
        return JsonResult.ok();
    }

    @GetMapping("/{id:[0-9]+}")
    @ApiOperation("根据id查询课程详情")
    @ApiOperationSupport(order = 230)
    @ApiImplicitParam(name = "id", value = "课程ID", required = true, example = "1", dataType = "long")
    public JsonResult<SubjectsStandardVO> getStandById(@PathVariable  Long id){
        log.debug("开始处理【根据id查询课程详情】的请求，参数：{}", id);
        SubjectsStandardVO standardVO=subjectsService.getStandradById(id);
        return JsonResult.ok(standardVO);
    }

    @GetMapping("")
    @ApiOperation("查询课程列表")
    @ApiOperationSupport(order = 240)
    public JsonResult<List<SubjectsListItemVO>> list(){
        log.debug("开始处理【查询课程列表】的业务，无参数");
        List<SubjectsListItemVO> list=subjectsService.list();
        return JsonResult.ok(list);
    }
}
